package Servlet;

import DAO.DAOFactory;
import DAO.StaffDAO;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

@WebServlet("/deleteStaff")
public class deleteStaffServlet extends HttpServlet {
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doGet(req, resp);
    }

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.setCharacterEncoding( "utf-8" );//设置编码格式，防止中文乱码
        resp.setCharacterEncoding( "utf-8" );
        String staffID = req.getParameter("staffID");
        StaffDAO staffDAO = (StaffDAO) DAOFactory.getStaffDAOInstance();
        PrintWriter out = resp.getWriter();
        resp.setContentType("text/html;charset=utf-8");
        if(staffDAO.deleteStaff(staffID)){
            // TODO 需要修改
            out.print("<script>alert('删除成功');window.location.href='Staff';</script>");
        }else{
            out.print("<script>alert('删除失败');window.location.href='Staff';</script>");
        }
    }
}
